<template>
  <div>
    <main>
      <div class="title" >{{ listName }}</div>
      <div class="courselist">
        <ul>
          <li v-for="(item, index) in courseList" :key="index" @click="goTo(item.id, item.type)">
            <div class="h224">
              <img v-lazy="item.image" alt="" />
              <!-- <span class="duration">33:06</span> -->
            </div>
            <div class="content">
              <div class="bt" v-if="courseId === '0'">{{ item.name }}</div>
              <div class="bt" v-else>{{ item.title }}</div>
              <div class="txt" v-html="item.memo"></div>
              <div class="num">{{ item.num }}人在学</div>
            </div>
          </li>
        </ul>
      </div>
      <h1 v-if="!courseList.length">暂无列表数据</h1>
    </main>
  </div>
</template>

<script>
import api from '@/config/api'
import { sendPost } from '@/utils/http'
export default {
  name: 'Basecourselist',
  data () {
    return {
      courseList: [],
      type: "",
      isRec: "",
      courseId:"",
      listName:'',

    }
  },

  methods: {
    goTo (id, type) {

      if (typeof type === 'undefined') {
        this.$router.push('/ptebase?id=' + id)
      }else{
        if(type=='3'||type=='6'){
          this.$router.push('cclcourseinfo?id=' + id+"&type="+type+"&isVip=1")
        }else{
          this.$router.push('cclcourseinfo?id=' + id+"&type="+type)
        }
      }
    },
    // 课程列表
    getCourseList () {
      if (this.type === '1' || this.type === '2' || this.type === '3' || this.type === '4' || this.type === '5' || this.type === '6' || this.type === '7') {
        sendPost(api.getCourseList, { type: this.type, offset: 0, limit: 99 }).then(res => {
          console.log(res);
          this.courseList = res.data
        })
      }
      // 精选好课
      if (this.isRec == 1 ) {
        sendPost(api.getCourseList, { isRec: '1', offset: 0, limit: 99 }).then(res => {
          // console.log(res);
          this.courseList = res.data
        })
      }
      // 免费好课
      if (this.courseId == '0') {
        sendPost(api.getFreeCourseList, { courseId: '0', offset: 0, limit: 9 }).then(res => {
          console.log(res);
          this.courseList = res.data
        })
      }
    },
  },
  created () {
    var query=this.$route.query;
    if(query.type){
      this.type=query.type
    }
    if(query.isRec){
      this.isRec=query.isRec
    }
    if(query.courseId){
      this.courseId=query.courseId
    }
    if(query.listName){
      this.listName=query.listName
    }else{
      this.listName='课程'
    }
    this.getCourseList()
  }
}
</script>

<style>
body,
html {
  background-color: #fff;
}
</style>
<style lang="less" scoped>
main {
  width: 75rem;
  margin: auto;
  margin-bottom: 15.625rem;
  .title {
    font-size: 2rem;
    color: #333;
    margin: 2.8125rem 0;
  }
  .courselist {
    ul {
      display: flex;
      flex-wrap: wrap;
      :nth-child(3n) {
        margin-right: 0;
      }
      li {
        width: 24rem;
        height: 22.875rem;
        background: #ffffff;
        border: 1px solid #ededed;
        box-sizing: border-box;
        margin-right: 1.5rem;
        margin-bottom: 3.125rem;
        position: relative;

        .h224 {
          height: 14rem;
          position: relative;
          cursor: pointer;
          img {
            width: 100%;
            height: 100%;
            vertical-align: middle;
          }
          .duration {
            position: absolute;
            width: 3.75rem;
            height: 1.5rem;
            right: 10px;
            bottom: 10px;
            background-color: #000;
            opacity: 0.4;
            border-radius: 0.125rem;
            text-align: center;
            line-height: 1.5rem;
            color: #fff;
          }
        }
        .content {
          // height: 9.25rem;
          // background-color: #eee;
          box-sizing: border-box;

          .bt {
            padding: 0 1.25rem;
            height: 3.4375rem;
            line-height: 3.4375rem;
            font-size: 1.25rem;
            color: #666;
          }
          .txt {
            font-size: 0.875rem;
            color: #999;
            height: 2.5rem;
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: wrap;
            padding: 0 1.25rem;
          }
          .num {
            width: 100%;
            bottom: 1.25rem;
            text-align: right;
            color: #999;
            margin-top: 1rem;
            padding-right: 1.25rem;
          }
        }
      }
    }
  }
}
</style>
